package com.wtgroup.demo.mianshi.算法.二叉树.model;

/**
 * @author L&J
 * @version 0.0.0
 * @email liuhejun108@163.com
 * @date 2019/9/7 23:21
 */
public class Node<T> {
    public enum NodeTypeEnum {
        Root,
        Left,
        Right;
    }

    public T       data;
    public Node<T> left;
    public Node<T> right;
    public Node<T> parent;

    public Node() {
    }

    public Node( T data ) {
        this.data = data;
    }

    public Node( T data, Node<T> left, Node<T> right, Node<T> parent ) {
        this.data = data;
        this.left = left;
        this.right = right;
        this.parent = parent;
    }

    public void appendLeft( Node<T> left ) {
        this.left = left;
        this.left.parent = this;
    }

    public void appendRight( Node<T> right ) {
        this.right = right;
        this.right.parent = this;
    }

    public boolean isEmpty() {
        return data == null;
    }

    public T getData() {
        return data;
    }

    public Node<T> getLeft() {
        return left;
    }

    public Node<T> getRight() {
        return right;
    }

    public Node<T> getParent() {
        return parent;
    }

    @Override
    public String toString() {
        return data == null ? null : data.toString();
    }

    public String toFullString() {
        final StringBuilder sb = new StringBuilder("Node{");
        sb.append(data)
                .append("[")
                .append(parent.data)
                .append(", ")
                .append(left.data)
                .append(", ")
                .append(right.data)
                .append("]")
                .append('}');
        return sb.toString();
    }
}
